<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 菜单管理
 *
 * @author Chen Xiaole
 *
 * @SWG\Model(id="Menu")
 * @SWG\Property(name="id", type="integer", description="ID")
 * @SWG\Property(name="parents", type="Menu", description="父级ID")
 * @SWG\Property(name="primary", type="Menu", description="一级ID")
 * @SWG\Property(name="name", type="string", description="菜单名称")
 * @SWG\Property(name="route", type="string", description="路由别名")
 * @SWG\Property(name="status", type="string", description="是否有效，有效：Yes，无效：No")
 * @SWG\Property(name="sort", type="integer", description="排序")
 */
class Menu extends Model
{
	protected $table = 'menus';

	/**
	 * 所属父级
	 */
	public function parents()
	{
		return $this->belongsTo('App\Models\Menu', 'pid');
	}

    public function childmenus()
    {
        return $this->hasMany('App\Models\Menu', 'pid')->where('status','Yes')->latest('sort');
    }
}
